<template>
    <div id="multiAngle" class="flex-start">
        <div class="multiAngle-content flex-center">
            <img class="content-size-i ani-op" :src="thumpImgsArry[currentAngle].src" alt="" v-if="thumpImgsArry[currentAngle] && thumpImgsArry[currentAngle].type===0" :key="currentAngle">
            <div v-if="thumpImgsArry[currentAngle] && thumpImgsArry[currentAngle].type === 1" :key="currentAngle" class="ma-video-container flex-center">
                <video class="content-size-v ani-op" :src="thumpImgsArry[currentAngle].src" v-show="showVideo" controls autoplay controlsList="nodownload" ref="video"></video>
            </div>
        </div>
        <div class="multiAngle-description">
            <div class="thump-container align-center" v-for="(item, index) in thumpImgsArry" :key="item.src" @click="changeAngle(index)">
                <div :class="['thump-img',{'active':currentAngle===index}]">
                    <img :src="item.thumbSrc" alt="">
                    <div class="img-type">{{item.type === 0 ? '图片':'视频'}}</div>
                </div>
                <div class="thump-title">{{item.title}}</div>
            </div>
            <div class="thump-handle flex-center">
                <div class="change page-left flex-center pointer" @click="prevImg">
                    <img src="../../assets/img/page-up.png" alt="加载失败">
                </div>
                <div class="change page-right flex-center pointer" @click="nextImg">
                    <img src="../../assets/img/page-down.png" alt="加载失败">
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import mixin from '../../mixin/mixin'
export default {
    name: "MultiAngle",
    mixins: [mixin],
    data() {
        return {
            thumpImgsArry: [],
            currentAngle: 0,
            showVideo: false,
        }
    },
    mounted() {
        if (this.bsr.angles) {
            this.bsr.angles.forEach(v => {
                let obj = { src: '', thumbSrc: '', title: '', type: '' }
                let thumbSuffix = this.getFileSuffix(v.thumb_name)
                let fileSuffix = this.getFileSuffix(v.file_name)
                obj.title = v.text
                obj.type = v.type
                obj.thumbSrc = window.$DATADIR + `resc/MultiAngle/${this.bsr.id}/${v.thumb_name.replace(/\.(?=[a-z])[a-z]{2,3}[a-z0-9]$/i, thumbSuffix)}`
                obj.src = window.$DATADIR + `resc/MultiAngle/${this.bsr.id}/${v.type === 0 ? v.file_name.replace(/\.(?=[a-z])[a-z]{2,3}[a-z0-9]$/i, fileSuffix) : v.file_name.replace(/\.(?=[a-z])[a-z]{2,3}[a-z0-9]$/i, '.bosm')}`
                this.thumpImgsArry.push(obj)
            })
            if (this.thumpImgsArry[this.currentAngle].type === 1) {
                this.showVideo = true
            }
            console.log(this.thumpImgsArry)
        }

        this.$nextTick(() => {
            this.$refs.video['disablePictureInPicture'] = true
        })
    },
    watch: {
        currentAngle(nval) {
            if (this.thumpImgsArry[nval].type === 1) {
                this.showVideo = false
                this.$nextTick(() => {
                    this.$refs.video['disablePictureInPicture'] = true
                    this.$refs.video.oncanplay = () => {
                        this.showVideo = true
                    }
                })
            }
        }
    },
    methods: {
        changeAngle(val) {
            this.currentAngle = val

        },
        prevImg() {
            if (this.currentAngle <= 0) return
            --this.currentAngle
        },
        nextImg() {
            if (this.currentAngle >= this.thumpImgsArry.length - 1) return
            ++this.currentAngle
        }
    },
}
</script>

<style lang="scss">
#multiAngle {
    max-width: 100vw;
    height: calc(100vh - 30px);
    @keyframes opacity {
        0% {
            opacity: 0;
        }
        100% {
            opacity: 1;
        }
    }
    .ani-op {
        animation: opacity 0.7s ease forwards;
    }
    .multiAngle-content {
        background-color: #d1d4d4;
        flex: 1;
        height: 100%;
        overflow: hidden;
        .ma-video-container {
            height: calc(100% - 40px);
        }

        .content-size-i {
            // width: calc(100% - 42px);
            max-width: calc(100% - 42px);
            height: calc(100% - 40px);
        }
        .content-size-v {
            // width: 100%;
            max-width: calc(100% - 42px);
            height: 100%;
            // height: calc(100% - 180px);
        }

        video::-webkit-media-controls-fullscreen-button {
            display: none;
        }
    }
    .multiAngle-description {
        width: 200px;
        background: #edeff2;
        height: 100%;
        padding-top: 18px;
        box-sizing: border-box;
        padding-bottom: 50px;
        overflow: auto;
        overflow-x: hidden;
        .thump-container {
            margin-bottom: 40px;
        }
        .active {
            border: 3px solid #4894ff;
        }
        .thump-img {
            width: 160px;
            height: 90px;
            border-radius: 4px;
            margin-bottom: 14px;
            overflow: hidden;
            position: relative;
            box-sizing: border-box;
            .img-type {
                position: absolute;
                top: 0;
                left: 0;
                width: 40px;
                height: 20px;
                line-height: 20px;
                font-size: 12px;
                text-align: center;
                color: #fff;
                background: rgba(0, 0, 0, 1);
                opacity: 0.5;
                border-radius: 4px 0px 4px 0px;
            }
            img {
                width: 100%;
                height: 100%;
            }
        }
        .thump-handle {
            position: fixed;
            bottom: 0;
            right: 0;
            width: 200px;
            height: 50px;
            background-color: #fff;
            .change {
                width: 32px;
                height: 32px;
                background-color: #fff;
                border: 1px solid rgba(72, 148, 255, 1);
                img {
                    width: 11px;
                    height: 11px;
                }
            }
            .page-change-arrows {
                width: 64px;
                margin-left: 27px;
            }
            .page-left {
                border-radius: 8px 0px 0px 8px;
            }
            .page-right {
                border-radius: 0px 8px 8px 0px;
                border-left: 1px solid rgba(72, 148, 255, 1);
            }
        }
    }
}
</style>
